﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using EnvironmentManagerSystem.BLL;
using EnvironmentManagerSystem.MODE;
using AjaxPro;
namespace EnvironmentManagerSystem.SearchQuery
{
    public partial class SelectDevelopprojectbasicinfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                BindGridView();
                DropDownListBind(string.Empty);
            }
        }

        #region GridView
        private void BindGridView()
        {
            // 获取GridView排序数据列及排序方向   
            string sortExpression = this.GridView1.Attributes["SortExpression"];
            string sortDirection = this.GridView1.Attributes["SortDirection"];
            // 调用业务数据获取方法   
            DataTable dtBind = this.getDB();
            // 根据GridView排序数据列及排序方向设置显示的默认数据视图   
            if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
            {
                dtBind.DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
            }
            // GridView绑定并显示数据   
            this.GridView1.DataSource = dtBind;
            this.GridView1.DataBind();
        }
        // DataTable 数据源     
        private DataTable getDB()
        {
            DataTable dt = NoticeService.GetSelectAll();
            return dt;
        }
        public SortDirection GridViewSortDirection
        {
            get
            {
                if (ViewState["sortDirection"] == null)
                    ViewState["sortDirection"] = SortDirection.Ascending;
                return (SortDirection)ViewState["sortDirection"];
            }
            set { ViewState["sortDirection"] = value; }
        }
        private void SortGridView(string sortExpression, string direction)
        {
            DataTable dt = getDB();
            DataView dv = new DataView(dt);
            dv.Sort = sortExpression + direction;
            GridView1.DataSource = dv; //将DataView绑定到GridView上
            GridView1.DataBind();
        }
        //处理GridView的排序事件
        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (GridViewSortDirection == SortDirection.Ascending) //设置排序方向
            {
                GridViewSortDirection = SortDirection.Descending;
                SortGridView(sortExpression, " DESC");
            }
            else
            {
                GridViewSortDirection = SortDirection.Ascending;
                SortGridView(sortExpression, " ASC");
            }
        }
        #endregion

        #region DropDownListBind
        public void DropDownListBind(string Deparatment)
        {
            ddlZuZhiRen.DataSource = EnvironmentManagerSystem.BLL.XIANGMU.GetFuzeren(Deparatment);
            ddlZuZhiRen.DataTextField = "UserName";
            ddlZuZhiRen.DataValueField = "ID";
            ddlZuZhiRen.DataBind();
            this.ddlZuZhiRen.Items.Insert(0, new ListItem("待定", "待定"));
        }
        #endregion

        #region LinkButton_Click
        protected void lbtnSelect_Click(object sender, EventArgs e)
        {
            lbtnBind();
        }
        private void lbtnBind()
        {
            GridView1.DataSource = NoticeService.GetSelect(txtProjectName.Text, ddlZuZhiRen.SelectedItem.Text);
            GridView1.DataBind();
        }
        #endregion
    }
}
